<template>
  <!-- 百人场-飞机详情 -->
  <el-dialog v-if="props.show" :modelValue="props.show" custom-class="detailData" :title=" selectToLabel(indexStore.gameArray, props.checkedItem.game_id)+' 详情'" :close-on-click-modal="false"
    :close-on-press-escape="false" @close="onHideDetails">
    <div class="border-box">
      <template v-for="(item, index) in data.filArr" :key="index">
        <div class="flex list" v-if="index <= 7">
          <div class="width20">
            {{ item.label }}
          </div>
          <div class=" ">
            <span v-if="item.key == 'win'" :class="colorClass(item.value)">
              {{ item.value }}</span>
            <span v-else>{{ item.value }}</span>
          </div>
        </div>
      </template>
      <div class="fily">
        <template v-for="(item, index) in data.filArr.filter((item, index) => index > 7)" :key="index">
          <div class="flight" v-if="item.key == 'flight_multiplier'">
            <div class="list">
              <div class="width20">
                {{ item.label }}
              </div>
              <div class="">
                <span>{{ item.value }}</span>
              </div>
            </div>
          </div>
          <div class="fily-list list" v-else>
            <div class="width50">
              {{ item.label }}
            </div>
            <div class="">
              <span>{{ item.value }}</span>
            </div>
          </div>
        </template>
      </div>
    </div>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive, toRefs, watch } from 'vue'
import { getGameReportDetails } from '@/api/player'
import { setTimestampTime } from '@/utils/time'
import { BigWan } from '@/utils/math'
import { selectToLabel, colorClass } from '@/utils/index'
import { useStore } from '@/stores/index'
const indexStore = useStore()

const props = defineProps({
  show: {
    type: Boolean,
    default: () => {
      return false
    }
  },
  checkedItem: {
    type: Object,
    default: () => {
      return {}
    }
  }
})

interface FilArr {
  label: string,
  value: any,
  key: string
}

const data = reactive({
  filArr: [] as FilArr[],
})

watch(
  () => [props.checkedItem,props.show],
  async (value) => {
    if (value[0] && value[1]) {
      gameDetails()
    }
  },
)

// 详情
const gameDetails = async() => {
  let query = {
    log_details_id: props.checkedItem.log_details_id,
    game_id: props.checkedItem.game_id
  }
  let res = {} as any
  if(!props.checkedItem.log_json){
    res = await getGameReportDetails(query)
  }else{
    res = JSON.parse(props.checkedItem.log_json)
  }
  console.log('百人场详情',res);
  data.filArr = [
    { label: '游戏', value: selectToLabel(indexStore.gameArray, props.checkedItem.game_id), key: 'game_id' },
    { label: '牌局编号', value: props.checkedItem.round_id_str, key: 'round_id_str' },
    { label: '时间', value: setTimestampTime(props.checkedItem.save_time_stamp), key: 'created_time_stamp' },
    { label: '当局总下注', value: BigWan(res.total_bet), key: 'total_bet' },
    { label: '当局真人参与人数', value: res.join_count, key: 'join_count' },
    { label: '本局下注', value: BigWan(props.checkedItem.bet), key: 'bet' },
    { label: '结果', value: BigWan(props.checkedItem.win - props.checkedItem.bet), key: 'win' },
    { label: '本局飞行倍数', value: BigWan(res.flight_multiplier), key: 'flight_multiplier' },
    { label: '区域一下注金额', value: BigWan(res.left_bet), key: 'left_bet' },
    { label: '区域二下注金额', value: BigWan(res.right_bet), key: 'right_bet' },
    { label: '区域一返奖结果', value: BigWan(res.left_delta), key: 'left_delta' },
    { label: '区域二返奖结果', value: BigWan(res.right_delta), key: 'right_delta' },
    { label: '区域一返奖倍数', value: BigWan(res.left_click_multiplier), key: 'left_click_multiplier' },
    { label: '区域二返奖倍数', value: BigWan(res.right_click_multiplier), key: 'right_click_multiplier' },
    { label: '区域一是否自动提现', value: res.left_auto_cash_out > 0 ? '是' : '否', key: 'left_auto_cash_out' },
    { label: '区域二是否自动提现', value: res.right_auto_cash_out > 0 ? '是' : '否', key: 'right_auto_cash_out' },
    { label: '自动提现设置倍数', value: BigWan(res.left_auto_cash_out), key: 'left_auto_cash_out' },
    { label: '自动提现设置倍数', value: BigWan(res.right_auto_cash_out), key: 'right_auto_cash_out' },
  ]
}

// 重置
const emit = defineEmits(['onHideDetails'])
const onHideDetails = () => {
  emit('onHideDetails', false)
}
</script>
<style scoped lang="scss">
.border-box {
  padding-bottom: 40px;
  font-size: 14px;
  color: var(--text);
}

.fily {
  display: flex;
  flex-wrap: wrap;
  width: 100%;

  .fily-list {
    width: 50%;
  }
}

.flight {
  width: 100%;
}

.list {
  font-weight: bold;
  height: 36px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--el-border-color-lighter);
}
</style>